function game(el) {
    this.el = document.querySelector(el)
    //地图
    this.map = new map(this.el)
    this.map.create()

    //食物
    this.food = new food(this.el)
    this.food.create()

    //蛇
    this.she = new she(this.el)
    this.she.create()
}

game.prototype.start=function(){
    setInterval(() =>{
        //蛇动
        this.she.move()

        //判断吃食物
        let sheX = this.she.sheObj[0].x*20
        let sheY = this.she.sheObj[0].y*20
        let foodX = this.food.foodX
        let foodY = this.food.foodY

        if (sheX == foodX && sheY == foodY){
            // alert('zh')
            let last = this.she.sheObj[this.she.sheObj.length-1]
            this.she.sheObj.push({
                x:last.x,y:last.y,color:last.color,el:null
            })
            this.she.create()
            //食物动
            this.food.move()
        }
    },50)

    //监控键盘动态更新蛇的方向
    document.addEventListener('keydown', (e) => {
        e=e || window.event
        //获取键盘
        switch (e.keyCode) {
            case 38:
                if (this.she.direction == 'bottom'){
                    alert('游戏结束')
                }
                this.she.direction='top'
            break;
            case 40:
                if (this.she.direction == 'top'){
                    alert('游戏结束')
                }
                this.she.direction='bottom'
            break;
            case 37:
                if (this.she.direction == 'right'){
                    alert('游戏结束')
                }
                this.she.direction='left'
            break;
            case 39:
                if (this.she.direction == 'left'){
                    alert('游戏结束')
                }
                this.she.direction='right'
            break;
        }
    })
}